package cn.hx.whh.automaticticket.constant;

import android.app.Activity;
import android.os.Build;
import android.text.TextUtils;

import java.util.Timer;
import java.util.TimerTask;

import cn.hx.whh.automaticticket.base.BaseBean;
import cn.hx.whh.automaticticket.entity.Employee;
import cn.hx.whh.automaticticket.netword.HttpUtils;
import cn.hx.whh.automaticticket.netword.Interfaceabstract.HttpInterface;
import cn.hx.whh.automaticticket.netword.Interfaceabstract.OKHttpListener;
import cn.hx.whh.automaticticket.params.LoginReport;

public final class Constants{
    private static String account = "admin";
    private static String password = "123456";
    /**
     * 设备序列号
     */
    private static String Device_Serial;

    /**
     * 设备序列号
     */
    public static Integer Device_Type = 1;


    /**
     * 获取设备的序列号
     *
     * @return String 设备的序列号
     */
    public static String getSerialNumber() {
        if (Device_Serial == null || "".equals(Device_Serial)) {
            Device_Serial = Build.SERIAL;
        }
        return Device_Serial;
    }

    private static Timer timer;
    private static TimerTask task;
    static {
        timer = new Timer(true);
        task = new TimerTask() {
            public void run() {
                localLogin();
            }
        };
        timer.schedule(task, 1000 , 1000 * 60 * 20);
    }

    private static void localLogin(){
        LoginReport report=new LoginReport(); //
        report.account = account;
        report.password = password;
        // TODO 登录校验 begin
        HttpUtils.Post(httpInterface, HttpUrls.sys_app_login, report.toMapUtils(),null, Employee.getInstance(), BaseBean.class, new OKHttpListener<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                Employee employee = (Employee) bean.params;
                if(employee.getAccessToken()==null||"".equals(employee.getAccessToken())){
                    localLogin();
                }
            }

            @Override
            public void handleResources(Object o) {

            }
        });
        // TODO 登录校验 end
    }
    private static HttpInterface httpInterface = new HttpInterface(){
        @Override
        public Activity getActivity() {
            return null;
        }

        @Override
        public boolean isDiscardHttp() {
            return false;
        }
    };
}